package kargo.suratkargokargotakip;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.HttpEntity;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import android.R.layout;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;

public class KargoTakipActivity extends Activity implements OnClickListener {
	private Bundle bundleResult = new Bundle();
	private static String CariKodu;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_kargo_takip);

		Button btnKargoTakip = (Button) findViewById(R.id.btnGetir);

		btnKargoTakip.setOnClickListener(this);

		Bundle extras = getIntent().getExtras();
		int deger = extras.getInt("SecenekButtonId");

		switch (deger) {
		case R.id.btnKargoTakipNoIle:
			ArrangeEditText();
			break;
		case R.id.btnBanaAitSiparisNoIle:
			ArrangeEditText();
			break;
		}

	}

	private EditText edit1;
	private EditText edit2;

	private void ArrangeEditText() {
		edit1 = (EditText) findViewById(R.id.editText1);
		edit2 = (EditText) findViewById(R.id.editText2);
		edit2.setEms(10);
		LinearLayout linear = (LinearLayout) findViewById(R.id.layout1);
		linear.removeViewInLayout(edit1);
	}



	@Override
	public void onClick(View v) {
		Getir();
	}

	private void Getir() {
	Bundle extras = getIntent().getExtras();
		CariKodu = extras.getString("CariKodu");

		int deger = extras.getInt("SecenekButtonId");

		HashMap<String, String> prms = new HashMap<String, String>();

		TableLayout tableLayout = (TableLayout) findViewById(R.id.tableLayout1);

		switch (deger) {
		case R.id.btnKargoTakipNoIle:
			ArrangeEditText();
			prms.put("takipNo", edit2.getText().toString());
			FillTableLayoutFromWebService.RequestXml(null,KargoTakipActivity.this, tableLayout,
					"http://webservices.suratkargo.com.tr/services.asmx",
					"TakipNodanKargoTeslimatBilgisi", prms, "TeslimatBilgisi",
					true);
			break;
		case R.id.btnBanaAitSiparisNoIle:
			ArrangeEditText();
			prms.put("GonderenCariKodu", CariKodu);
			prms.put("WebSiparisKodu", edit2.getText().toString());
			FillTableLayoutFromWebService.RequestXml(null,KargoTakipActivity.this, tableLayout,
					"http://webservices.suratkargo.com.tr/services.asmx",
					"WebSiparisKodu", prms, "NewDataSet", false);
			break;

		case R.id.butonUcretHesapla:
			ArrangeEditText();
			FillTableLayoutFromWebService.RequestXml(null,
					KargoTakipActivity.this,
					tableLayout,
					"http://webservices.suratkargo.com.tr/WebSiteServices.asmx",
					"GetIl", prms, "NewDataSet", false);
			break;
		}
	}



}
